<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>全网最全正则表达式总结 | 冰河技术</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/favicon.ico">
    <script charset="utf-8" async="async" src="/js/jquery.min.js"></script>
    <script charset="utf-8" async="async" src="/js/global.js"></script>
    <script charset="utf-8" async="async" src="/js/fingerprint2.min.js"></script>
    <script charset="utf-8" async="async" src="https://v1.cnzz.com/z_stat.php?id=1281063564&amp;web_id=1281063564"></script>
    <script charset="utf-8" async="async" src="https://s9.cnzz.com/z_stat.php?id=1281064551&amp;web_id=1281064551"></script>
    <script>
            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?d091d2fd0231588b1d0f9231e24e3f5e";
              var s = document.getElementsByTagName("script")[0];
              s.parentNode.insertBefore(hm, s);
            })();
            </script>
    <meta name="description" content="包含：编程语言，开发技术，分布式，微服务，高并发，高可用，高可扩展，高可维护，JVM技术，MySQL，分布式数据库，分布式事务，云原生，大数据，云计算，渗透技术，各种面试题，面试技巧...">
    <meta property="article:modified_time" content="2022-05-23T11:30:51.000Z">
    <meta property="og:title" content="全网最全正则表达式总结">
    <meta property="og:type" content="article">
    <meta property="og:url" content="/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html">
    <meta name="twitter:title" content="全网最全正则表达式总结">
    <meta name="twitter:url" content="/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="robots" content="all">
    <meta name="author" content="冰河">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="keywords" content="冰河，冰河技术, 编程语言，开发技术，分布式，微服务，高并发，高可用，高可扩展，高可维护，JVM技术，MySQL，分布式数据库，分布式事务，云原生，大数据，云计算，渗透技术，各种面试题，面试技巧">
    <meta name="apple-mobile-web-app-capable" content="yes">
    
    <link rel="preload" href="/assets/css/0.styles.ab888ebb.css" as="style"><link rel="preload" href="/assets/css/styles.css?v=1653305936337" as="style"><link rel="preload" href="/assets/js/cg-styles.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-app.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-4.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-3.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-46.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-5.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-6.js?v=1653305936337" as="script">
    <link rel="stylesheet" href="/assets/css/0.styles.ab888ebb.css"><link rel="stylesheet" href="/assets/css/styles.css?v=1653305936337">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">冰河技术</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="核心技术" class="dropdown-title"><span class="title">核心技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="nav-link">
  Java基础
</a></li><li class="dropdown-subitem"><a href="/md/core/java/advanced/default.html" class="nav-link">
  Java进阶
</a></li><li class="dropdown-subitem"><a href="/md/core/java/senior/default.html" class="nav-link">
  Java高级
</a></li><li class="dropdown-subitem"><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="nav-link">
  Java8新特性
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/spring/ioc/2022-04-04-001-聊聊Spring注解驱动开发那些事儿.html" class="nav-link">
  IOC核心技术
</a></li><li class="dropdown-subitem"><a href="/md/core/spring/aop/default.html" class="nav-link">
  AOP核心技术
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/jvm/2022-04-18-001-JVM调优的几种场景.html" class="nav-link">
  JVM调优技术
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="性能调优" class="dropdown-title"><span class="title">性能调优</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/performance/jvm/default.html" class="nav-link">
  JVM性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/tomcat/default.html" class="nav-link">
  Tomcat性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/mysql/default.html" class="nav-link">
  MySQL性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/system/default.html" class="nav-link">
  操作系统性能调优
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="并发编程" class="dropdown-title"><span class="title">并发编程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/concurrent/bottom/default.html" class="nav-link">
  底层技术
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/source/2020-03-30-001-一文搞懂线程与多线程.html" class="nav-link">
  源码分析
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/basics/2020-03-30-001-明明中断了线程，却为何不起作用呢？.html" class="nav-link">
  基础案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/ActualCombat/default.html" class="nav-link">
  实战案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/interview/default.html" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/framework/default.html" class="nav-link">
  系统架构
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="框架源码" class="dropdown-title"><span class="title">框架源码</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/frame/spring/default.html" class="nav-link">
  Spring源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/springmvc/default.html" class="nav-link">
  SpringMVC源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/mybatis/default.html" class="nav-link">
  MyBatis源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/dubbo/default.html" class="nav-link">
  Dubbo源码
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分布式" class="dropdown-title"><span class="title">分布式</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          缓存技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/cache/default.html" class="nav-link">
  Redis
</a></li></ul></li><li class="dropdown-item"><h4>
          服务注册发现
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/zookeeper/default.html" class="nav-link">
  Zookeeper
</a></li></ul></li><li class="dropdown-item"><h4>
          消息中间件
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mq/rabbitmq/default.html" class="nav-link">
  RabbitMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/rocketmq/default.html" class="nav-link">
  RocketMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/kafka/default.html" class="nav-link">
  Kafka
</a></li></ul></li><li class="dropdown-item"><h4>
          网络通信
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/netty/default.html" class="nav-link">
  Netty
</a></li></ul></li><li class="dropdown-item"><h4>
          远程调用
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/dubbo/default.html" class="nav-link">
  Dubbo
</a></li></ul></li><li class="dropdown-item"><h4>
          数据库
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mongodb/default.html" class="nav-link">
  MongoDB
</a></li></ul></li><li class="dropdown-item"><h4>
          搜索引擎
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/es/default.html" class="nav-link">
  ElasticSearch
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="微服务" class="dropdown-title"><span class="title">微服务</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springboot/default.html" class="nav-link">
  SpringBoot
</a></li><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloudAlibaba
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/middleware/bytecode/2022-04-11-001-工作多年的你依然重复做着CRUD-是否接触过这种技术.html" class="nav-link">
  字节码编程
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/threadpool/default.html" class="nav-link">
  手写线程池
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/limiter/default.html" class="nav-link">
  分布式限流
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/independent/default.html" class="nav-link">
  开源项目
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloud Alibaba实战
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="渗透技术" class="dropdown-title"><span class="title">渗透技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/hack/environment/2022-04-17-001-安装Kali系统.html" class="nav-link">
  基础环境篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/tools/2022-04-17-001-使用Easy-Creds工具攻击无线网络.html" class="nav-link">
  渗透工具篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/horse/2022-05-02-001-各种一句话木马大全.html" class="nav-link">
  木马篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sql/2022-05-02-001-sqli-labs-master下载与安装.html" class="nav-link">
  SQL注入篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/shell/2022-05-02-001-各种解析漏洞拿shell.html" class="nav-link">
  漏洞拿Shell篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/crack/2022-05-02-001-使用rarcrack暴力破解RAR-ZIP-7Z压缩包.html" class="nav-link">
  暴力破解篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/bash/2022-05-02-001-3389脚本开启代码(vbs版).html" class="nav-link">
  渗透脚本篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/raising/2022-05-02-001-数据库提权.html" class="nav-link">
  数据与系统提权篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/client/2022-05-02-001-浏览器渗透.html" class="nav-link">
  客户端渗透篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sociology/2022-05-02-001-Metasploit之社会工程学工具包.html" class="nav-link">
  社会工程学
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/question/2022-05-02-001-HTTP错误4031禁止访问-执行访问被拒绝.html" class="nav-link">
  问题记录篇
</a></li></ul></div></div><div class="nav-item"><a href="/md/interview/2022-04-18-001-面试必问-聊聊JVM性能调优.html" class="nav-link">
  面试必问系列
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📚PDF" class="dropdown-title"><span class="title">📚PDF</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          出版图书
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-深入理解分布式事务.html" class="nav-link">
  《深入理解分布式事务：原理与实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-MySQL技术大全.html" class="nav-link">
  《MySQL技术大全：开发、优化与运维实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-海量数据处理与大数据技术实战.html" class="nav-link">
  《海量数据处理与大数据技术实战》
</a></li></ul></li><li class="dropdown-item"><h4>
          电子书籍
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/pdf/2022-03-30-《冰河的渗透实战笔记》电子书，442页，37万字，正式发布.html" class="nav-link">
  冰河的渗透实战笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="关于" class="dropdown-title"><span class="title">关于</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/about/me/about-me.html" class="nav-link">
  关于自己
</a></li><li class="dropdown-item"><!----> <a href="/md/about/study/default.html" class="nav-link">
  关于学习
</a></li><li class="dropdown-item"><!----> <a href="/md/about/job/default.html" class="nav-link">
  关于职场
</a></li></ul></div></div><div class="nav-item"><a href="https://space.bilibili.com/517638832" target="_blank" rel="noopener noreferrer" class="nav-link external">
  B站
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/binghe001/BingheGuide" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="核心技术" class="dropdown-title"><span class="title">核心技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="nav-link">
  Java基础
</a></li><li class="dropdown-subitem"><a href="/md/core/java/advanced/default.html" class="nav-link">
  Java进阶
</a></li><li class="dropdown-subitem"><a href="/md/core/java/senior/default.html" class="nav-link">
  Java高级
</a></li><li class="dropdown-subitem"><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="nav-link">
  Java8新特性
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/spring/ioc/2022-04-04-001-聊聊Spring注解驱动开发那些事儿.html" class="nav-link">
  IOC核心技术
</a></li><li class="dropdown-subitem"><a href="/md/core/spring/aop/default.html" class="nav-link">
  AOP核心技术
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/jvm/2022-04-18-001-JVM调优的几种场景.html" class="nav-link">
  JVM调优技术
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="性能调优" class="dropdown-title"><span class="title">性能调优</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/performance/jvm/default.html" class="nav-link">
  JVM性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/tomcat/default.html" class="nav-link">
  Tomcat性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/mysql/default.html" class="nav-link">
  MySQL性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/system/default.html" class="nav-link">
  操作系统性能调优
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="并发编程" class="dropdown-title"><span class="title">并发编程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/concurrent/bottom/default.html" class="nav-link">
  底层技术
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/source/2020-03-30-001-一文搞懂线程与多线程.html" class="nav-link">
  源码分析
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/basics/2020-03-30-001-明明中断了线程，却为何不起作用呢？.html" class="nav-link">
  基础案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/ActualCombat/default.html" class="nav-link">
  实战案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/interview/default.html" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/framework/default.html" class="nav-link">
  系统架构
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="框架源码" class="dropdown-title"><span class="title">框架源码</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/frame/spring/default.html" class="nav-link">
  Spring源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/springmvc/default.html" class="nav-link">
  SpringMVC源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/mybatis/default.html" class="nav-link">
  MyBatis源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/dubbo/default.html" class="nav-link">
  Dubbo源码
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分布式" class="dropdown-title"><span class="title">分布式</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          缓存技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/cache/default.html" class="nav-link">
  Redis
</a></li></ul></li><li class="dropdown-item"><h4>
          服务注册发现
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/zookeeper/default.html" class="nav-link">
  Zookeeper
</a></li></ul></li><li class="dropdown-item"><h4>
          消息中间件
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mq/rabbitmq/default.html" class="nav-link">
  RabbitMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/rocketmq/default.html" class="nav-link">
  RocketMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/kafka/default.html" class="nav-link">
  Kafka
</a></li></ul></li><li class="dropdown-item"><h4>
          网络通信
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/netty/default.html" class="nav-link">
  Netty
</a></li></ul></li><li class="dropdown-item"><h4>
          远程调用
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/dubbo/default.html" class="nav-link">
  Dubbo
</a></li></ul></li><li class="dropdown-item"><h4>
          数据库
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mongodb/default.html" class="nav-link">
  MongoDB
</a></li></ul></li><li class="dropdown-item"><h4>
          搜索引擎
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/es/default.html" class="nav-link">
  ElasticSearch
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="微服务" class="dropdown-title"><span class="title">微服务</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springboot/default.html" class="nav-link">
  SpringBoot
</a></li><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloudAlibaba
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/middleware/bytecode/2022-04-11-001-工作多年的你依然重复做着CRUD-是否接触过这种技术.html" class="nav-link">
  字节码编程
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/threadpool/default.html" class="nav-link">
  手写线程池
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/limiter/default.html" class="nav-link">
  分布式限流
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/independent/default.html" class="nav-link">
  开源项目
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloud Alibaba实战
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="渗透技术" class="dropdown-title"><span class="title">渗透技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/hack/environment/2022-04-17-001-安装Kali系统.html" class="nav-link">
  基础环境篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/tools/2022-04-17-001-使用Easy-Creds工具攻击无线网络.html" class="nav-link">
  渗透工具篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/horse/2022-05-02-001-各种一句话木马大全.html" class="nav-link">
  木马篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sql/2022-05-02-001-sqli-labs-master下载与安装.html" class="nav-link">
  SQL注入篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/shell/2022-05-02-001-各种解析漏洞拿shell.html" class="nav-link">
  漏洞拿Shell篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/crack/2022-05-02-001-使用rarcrack暴力破解RAR-ZIP-7Z压缩包.html" class="nav-link">
  暴力破解篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/bash/2022-05-02-001-3389脚本开启代码(vbs版).html" class="nav-link">
  渗透脚本篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/raising/2022-05-02-001-数据库提权.html" class="nav-link">
  数据与系统提权篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/client/2022-05-02-001-浏览器渗透.html" class="nav-link">
  客户端渗透篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sociology/2022-05-02-001-Metasploit之社会工程学工具包.html" class="nav-link">
  社会工程学
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/question/2022-05-02-001-HTTP错误4031禁止访问-执行访问被拒绝.html" class="nav-link">
  问题记录篇
</a></li></ul></div></div><div class="nav-item"><a href="/md/interview/2022-04-18-001-面试必问-聊聊JVM性能调优.html" class="nav-link">
  面试必问系列
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📚PDF" class="dropdown-title"><span class="title">📚PDF</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          出版图书
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-深入理解分布式事务.html" class="nav-link">
  《深入理解分布式事务：原理与实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-MySQL技术大全.html" class="nav-link">
  《MySQL技术大全：开发、优化与运维实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-海量数据处理与大数据技术实战.html" class="nav-link">
  《海量数据处理与大数据技术实战》
</a></li></ul></li><li class="dropdown-item"><h4>
          电子书籍
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/pdf/2022-03-30-《冰河的渗透实战笔记》电子书，442页，37万字，正式发布.html" class="nav-link">
  冰河的渗透实战笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="关于" class="dropdown-title"><span class="title">关于</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/about/me/about-me.html" class="nav-link">
  关于自己
</a></li><li class="dropdown-item"><!----> <a href="/md/about/study/default.html" class="nav-link">
  关于学习
</a></li><li class="dropdown-item"><!----> <a href="/md/about/job/default.html" class="nav-link">
  关于职场
</a></li></ul></div></div><div class="nav-item"><a href="https://space.bilibili.com/517638832" target="_blank" rel="noopener noreferrer" class="nav-link external">
  B站
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/binghe001/BingheGuide" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Java基础</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="active sidebar-link">全网最全正则表达式总结</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>Java进阶</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/core/java/advanced/default.html" class="sidebar-link">关于我</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>Java高级</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/core/java/senior/default.html" class="sidebar-link">关于我</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>Java8新特性</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="sidebar-link">一张图带你领略Java8有哪些新特性</a></li><li><a href="/md/core/java/java8/2022-03-31-002-你知道Java8为什么引入Lambda表达式吗.html" class="sidebar-link">你知道Java8为什么要引入Lambda表达式吗？</a></li><li><a href="/md/core/java/java8/2022-03-31-003-Lambda表达式基础语法，都在这儿了.html" class="sidebar-link">Lambda表达式基础语法，都在这儿了！！</a></li><li><a href="/md/core/java/java8/2022-03-31-004-Lambda表达式典型案例，你想要的的都在这儿了.html" class="sidebar-link">Lambda表达式典型案例，你想要的的都在这儿了！！</a></li><li><a href="/md/core/java/java8/2022-03-31-005-一文搞懂函数式接口.html" class="sidebar-link">一文搞懂函数式接口</a></li><li><a href="/md/core/java/java8/2022-03-31-006-知识点总结，你都会了吗.html" class="sidebar-link">知识点总结，你都会了吗？</a></li><li><a href="/md/core/java/java8/2022-03-31-007-方法引用和构造器引用.html" class="sidebar-link">浅谈方法引用和构造器引用</a></li><li><a href="/md/core/java/java8/2022-03-31-008-关于Java8的Stream API,都在这儿了.html" class="sidebar-link">关于Java8的Stream API,都在这儿了</a></li><li><a href="/md/core/java/java8/2022-03-31-009-强大的Stream API，你了解吗.html" class="sidebar-link">强大的Stream API，你了解吗</a></li><li><a href="/md/core/java/java8/2022-03-31-010-Stream API有哪些中间操作,看完你也可以吊打面试官.html" class="sidebar-link">Stream API有哪些中间操作？看完你也可以吊打面试官！！</a></li><li><a href="/md/core/java/java8/2022-03-31-011-Java8中的Stream API有哪些终止操作.html" class="sidebar-link">Java8中的Stream API有哪些终止操作</a></li><li><a href="/md/core/java/java8/2022-03-31-012-关于并行流与串行流，你必须掌握这些.html" class="sidebar-link">关于并行流与串行流，你必须掌握这些！！</a></li><li><a href="/md/core/java/java8/2022-03-31-013-不了解Optional类，简历上别说你懂Java8.html" class="sidebar-link">不了解Optional类，简历上别说你懂Java8</a></li><li><a href="/md/core/java/java8/2022-03-31-014-接口中的默认方法和静态方法，你都掌握了吗.html" class="sidebar-link">接口中的默认方法和静态方法，你都掌握了吗？</a></li><li><a href="/md/core/java/java8/2022-03-31-015-关于Java8中的日期时间API，你需要掌握这些.html" class="sidebar-link">关于Java8中的日期时间API，你需要掌握这些！！</a></li><li><a href="/md/core/java/java8/2022-03-31-016-重复注解与类型注解，你真的学会了吗.html" class="sidebar-link">重复注解与类型注解，你真的学会了吗？</a></li><li><a href="/md/core/java/java8/2022-04-01-001-Java8新特性总结.html" class="sidebar-link">Java8新特性总结</a></li></ul></section></li></ul> </aside> <div><main class="page"> <div class="theme-default-content content__default"><h1 id="全网最全正则表达式总结"><a href="#全网最全正则表达式总结" class="header-anchor">#</a> 全网最全正则表达式总结</h1> <p><strong>大家好，我是冰河~~</strong></p> <p><strong>我用了两天时间整理了这些工作用常用的正则表达式，小伙伴们拿走，不谢～</strong></p> <p><strong>这次我把工作中总结的经常使用的正则表达式共享出来了，正是掌握了这些正则表达式，冰河平均每天比别人少写200行代码，极大的提高了研发效率，建议小伙伴们收藏，平时尝试着使用到自己的项目中！！</strong></p> <p>熟练的掌握正则表达式，能够帮助程序员以最快的速度写出最优雅的代码。</p> <p>冰河在多年的编程工作中，对使用过的正则表达式进行了梳理和总结，这些正则表达式能够帮助你节省很多的编码时间，往往一个简单的正则表达式就能够省略大量的<code>if...else...</code>代码。</p> <p>这次，冰河向小伙伴们公开了自己平时经常使用的正则表达式，希望能够为小伙伴们带来实质性的帮助。</p> <h2 id="冰河常用正则"><a href="#冰河常用正则" class="header-anchor">#</a> 冰河常用正则</h2> <p><strong>整数或者小数</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>+<span class="token punctuation">\</span>.<span class="token punctuation">{</span><span class="token number">0,1</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">0,2</span><span class="token punctuation">}</span>$ 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入数字</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>*$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入n位的数字</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>d<span class="token punctuation">{</span>n<span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入至少n位的数字</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>d<span class="token punctuation">{</span>n,<span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入m~n位的数字</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>d<span class="token punctuation">{</span>m,n<span class="token punctuation">}</span>$ 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入零和非零开头的数字</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span><span class="token number">0</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>*<span class="token punctuation">)</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入有两位小数的正实数</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>+<span class="token punctuation">(</span>.<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">)</span>?$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入有1~3位小数的正实数</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>+<span class="token punctuation">(</span>.<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">1,3</span><span class="token punctuation">}</span><span class="token punctuation">)</span>?$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入非零的正整数</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>+?<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>*$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入非零的负整数</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>-<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token number">0</span>-9*$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入长度为3的字符</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^.<span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入由26个英文字母组成的字符串</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span>A-Za-z<span class="token punctuation">]</span>+$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入由26个大写英文字母组成的字符串</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span>A-Z<span class="token punctuation">]</span>+$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入由26个小写英文字母组成的字符串</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span>a-z<span class="token punctuation">]</span>+$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入由数字和26个英文字母组成的字符串</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span>A-Za-z0-9<span class="token punctuation">]</span>+$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入由数字、26个英文字母或者下划线组成的字符串</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>w+$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>验证用户密码：</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span>a-zA-Z<span class="token punctuation">]</span><span class="token punctuation">\</span>w<span class="token punctuation">{</span><span class="token number">5,17</span><span class="token punctuation">}</span>$ 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>注：正确格式为：以字母开头，长度在6~18之间，只能包含字符、数字和下划线。</p> <p><strong>验证是否含有<code>^%&amp;',;=?$\</code>等字符</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>^%<span class="token operator">&amp;</span>',<span class="token punctuation">;</span><span class="token operator">=</span>?$<span class="token punctuation">\</span>x22<span class="token punctuation">]</span>+ 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>只能输入汉字</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token punctuation">\</span>u4e00-<span class="token punctuation">\</span>u9fa5<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">0</span>,<span class="token punctuation">}</span>$ 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>验证Email地址</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-+.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*@<span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*<span class="token punctuation">\</span>.<span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>验证Internet URL</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span>http<span class="token operator">|</span>https<span class="token punctuation">]</span>://<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">\</span>w-<span class="token punctuation">]</span>+<span class="token punctuation">\</span>.<span class="token punctuation">)</span>+<span class="token punctuation">[</span><span class="token punctuation">\</span>w-<span class="token punctuation">]</span>+<span class="token punctuation">(</span>/<span class="token punctuation">[</span><span class="token punctuation">\</span>w-./?%<span class="token operator">&amp;</span><span class="token operator">=</span><span class="token punctuation">]</span>*<span class="token punctuation">)</span>?$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>验证电话号码</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span><span class="token punctuation">\</span><span class="token punctuation">(</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">3,4</span><span class="token punctuation">}</span>-<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">3.4</span><span class="token punctuation">}</span>-<span class="token punctuation">)</span>?<span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">7,8</span><span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>正确格式为：XXX-XXXXXXX、XXXX- XXXXXXXX、XXX-XXXXXXX、XXX-XXXXXXXX、XXXXXXX和XXXXXXXX</p> <p><strong>验证身份证号（15位或18位数字）</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">15</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">18</span><span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>验证一年的12个月</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span><span class="token number">0</span>?<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">1</span><span class="token punctuation">[</span><span class="token number">0</span>-2<span class="token punctuation">]</span><span class="token punctuation">)</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>正确格式为：01～09和1～12</p> <p><strong>验证一个月的31天</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">((</span><span class="token number">0</span>?<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">((</span><span class="token number">1</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">|</span><span class="token number">30</span><span class="token operator">|</span><span class="token number">31</span><span class="token punctuation">)</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>正确格式为；01～09和1～31</p> <p><strong>匹配中文字符的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span><span class="token punctuation">\</span>u4e00-<span class="token punctuation">\</span>u9fa5<span class="token punctuation">]</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>匹配双字节字符(包括汉字在内)</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>^<span class="token punctuation">\</span>x00-<span class="token punctuation">\</span>xff<span class="token punctuation">]</span> 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>匹配空行的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">\</span>n<span class="token punctuation">[</span><span class="token punctuation">\</span>s<span class="token operator">|</span> <span class="token punctuation">]</span>*<span class="token punctuation">\</span>r
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>匹配html标签的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token operator">&lt;</span><span class="token punctuation">(</span>.*<span class="token punctuation">)</span><span class="token operator">&gt;</span><span class="token punctuation">(</span>.*<span class="token punctuation">)</span><span class="token operator">&lt;</span><span class="token punctuation">\</span>/<span class="token punctuation">(</span>.*<span class="token punctuation">)</span><span class="token operator">&gt;|</span><span class="token operator">&lt;</span><span class="token punctuation">(</span>.*<span class="token punctuation">)</span><span class="token punctuation">\</span>/<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>匹配首尾空格的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span>^<span class="token punctuation">\</span>s*<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span><span class="token punctuation">\</span>s*$<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>匹配Email地址的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-+.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*@<span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*<span class="token punctuation">\</span>.<span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>匹配HTML标记的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token operator">&lt;</span><span class="token punctuation">(</span><span class="token punctuation">\</span>S*?<span class="token punctuation">)</span><span class="token punctuation">[</span>^<span class="token operator">&gt;</span><span class="token punctuation">]</span>*<span class="token operator">&gt;</span>.*?<span class="token operator">|</span><span class="token operator">&lt;</span>.*? /<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：网上流传的版本太糟糕，上面这个也仅仅能匹配部分，对于复杂的嵌套标记依旧无能为力</p> <p><strong>匹配首尾空白字符的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>s*<span class="token operator">|</span><span class="token punctuation">\</span>s*$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等)，非常有用的表达式</p> <p><strong>匹配Email地址的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-+.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*@<span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*<span class="token punctuation">\</span>.<span class="token punctuation">\</span>w+<span class="token punctuation">(</span><span class="token punctuation">[</span>-.<span class="token punctuation">]</span><span class="token punctuation">\</span>w+<span class="token punctuation">)</span>*
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：表单验证时很实用</p> <p><strong>匹配网址URL的正则表达式</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>a-zA-z<span class="token punctuation">]</span>+://<span class="token punctuation">[</span>^<span class="token punctuation">\</span>s<span class="token punctuation">]</span>*
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：网上流传的版本功能很有限，上面这个基本可以满足需求</p> <p><strong>匹配帐号是否合法(字母开头，允许5-16字节，允许字母数字下划线)</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span>a-zA-Z<span class="token punctuation">]</span><span class="token punctuation">[</span>a-zA-Z0-9_<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">4,15</span><span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：表单验证时很实用</p> <p><strong>匹配国内电话号码</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span>-<span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">8</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">}</span>-<span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">7</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：匹配形式如 0511-4405222 或 021-87888822</p> <p><strong>匹配腾讯QQ号</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">4</span>,<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：腾讯QQ号从10000开始</p> <p><strong>匹配中国邮政编码</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">5</span><span class="token punctuation">}</span><span class="token punctuation">(</span>?<span class="token operator">!</span><span class="token punctuation">\</span>d<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：中国邮政编码为6位数字</p> <p><strong>匹配身份证</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">15</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">18</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：中国的身份证为15位或18位</p> <p><strong>匹配ip地址</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">\</span>d+<span class="token punctuation">\</span>.<span class="token punctuation">\</span>d+<span class="token punctuation">\</span>.<span class="token punctuation">\</span>d+<span class="token punctuation">\</span>.<span class="token punctuation">\</span>d+
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>评注：提取ip地址时有用</p> <p><strong>匹配特定数字</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*$ //匹配正整数
^-<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*$ //匹配负整数
^-?<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*$ //匹配整数
^<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span>$ //匹配非负整数（正整数 + <span class="token number">0</span>）
^-<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span>$ //匹配非正整数（负整数 + <span class="token number">0</span>）
^<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span><span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*$ //匹配正浮点数
^-<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span><span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token punctuation">)</span>$ //匹配负浮点数
^-?<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span><span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span>?<span class="token punctuation">\</span>.0+<span class="token operator">|</span><span class="token number">0</span><span class="token punctuation">)</span>$ //匹配浮点数
^<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span><span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span>?<span class="token punctuation">\</span>.0+<span class="token operator">|</span><span class="token number">0</span>$ //匹配非负浮点数（正浮点数 + <span class="token number">0</span>）
^<span class="token punctuation">(</span>-<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token operator">|</span><span class="token number">0</span><span class="token punctuation">\</span>.<span class="token punctuation">\</span>d*<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span>d*<span class="token punctuation">))</span><span class="token operator">|</span><span class="token number">0</span>?<span class="token punctuation">\</span>.0+<span class="token operator">|</span><span class="token number">0</span>$//匹配非正浮点数（负浮点数 + <span class="token number">0</span>）s
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br></div></div><p>评注：处理大量数据时有用，具体应用时注意修正。</p> <p><strong>匹配特定字符串</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span>A-Za-z<span class="token punctuation">]</span>+$//匹配由26个英文字母组成的字符串
^<span class="token punctuation">[</span>A-Z<span class="token punctuation">]</span>+$//匹配由26个英文字母的大写组成的字符串
^<span class="token punctuation">[</span>a-z<span class="token punctuation">]</span>+$//匹配由26个英文字母的小写组成的字符串
^<span class="token punctuation">[</span>A-Za-z0-9<span class="token punctuation">]</span>+$//匹配由数字和26个英文字母组成的字符串
^<span class="token punctuation">\</span>w+$//匹配由数字、26个英文字母或者下划线组成的字符串
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>评注：最基本也是最常用的一些表达式</p> <p><strong>校验密码强度</strong>例如密码的强度为：包含大小写字母和数字的组合，不能使用特殊字符，长度在8-10之间。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span>?<span class="token operator">=</span>.*<span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">)</span><span class="token punctuation">(</span>?<span class="token operator">=</span>.*<span class="token punctuation">[</span>a-z<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span>?<span class="token operator">=</span>.*<span class="token punctuation">[</span>A-Z<span class="token punctuation">]</span><span class="token punctuation">)</span>.<span class="token punctuation">{</span><span class="token number">8,10</span><span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>校验字符串</strong></p> <p>中文。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token punctuation">\</span><span class="token punctuation">\</span>u4e00-<span class="token punctuation">\</span><span class="token punctuation">\</span>u9fa5<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">0</span>,<span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>由数字、26个英文字母或下划线组成的字符串</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span><span class="token punctuation">\</span>w+$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>校验E-Mail 地址</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span><span class="token punctuation">\</span><span class="token punctuation">\</span>w<span class="token operator">!</span><span class="token comment">#$%&amp;'*+/=?^_`{|}~-]+(?:\\.[\\w!#$%&amp;'*+/=?^_`{|}~-]+)*@(?:[\\w](?:[\\w-]*[\\w])?\\.)+[\\w](?:[\\w-]*[\\w])?</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>校验身份证号码</strong>15位：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">7</span><span class="token punctuation">}</span><span class="token variable"><span class="token punctuation">((</span><span class="token number">0</span>\\d<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span><span class="token number">1</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">2</span>]<span class="token punctuation">))</span></span><span class="token punctuation">((</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token operator">|</span><span class="token number">1</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">)</span><span class="token operator">|</span><span class="token number">3</span><span class="token punctuation">[</span><span class="token number">0</span>-1<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>18位：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">5</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token variable"><span class="token punctuation">((</span><span class="token number">0</span>\\d<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span><span class="token number">1</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">2</span>]<span class="token punctuation">))</span></span><span class="token punctuation">((</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token operator">|</span><span class="token number">1</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">)</span><span class="token operator">|</span><span class="token number">3</span><span class="token punctuation">[</span><span class="token number">0</span>-1<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span>X<span class="token punctuation">)</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>校验日期</strong>“yyyy-mm-dd“ 格式的日期校验，已考虑平闰年。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span>?:<span class="token punctuation">(</span>?<span class="token operator">!</span>0000<span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">}</span>-<span class="token punctuation">(</span>?:<span class="token punctuation">(</span>?:0<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">1</span><span class="token punctuation">[</span><span class="token number">0</span>-2<span class="token punctuation">]</span><span class="token punctuation">)</span>-<span class="token punctuation">(</span>?:0<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">1</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">0</span>-8<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>?:0<span class="token punctuation">[</span><span class="token number">13</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">1</span><span class="token punctuation">[</span><span class="token number">0</span>-2<span class="token punctuation">]</span><span class="token punctuation">)</span>-<span class="token punctuation">(</span>?:29<span class="token operator">|</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>?:0<span class="token punctuation">[</span><span class="token number">13578</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">1</span><span class="token punctuation">[</span>02<span class="token punctuation">]</span><span class="token punctuation">)</span>-31<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>?:<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">(</span>?:0<span class="token punctuation">[</span><span class="token number">48</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">2468</span><span class="token punctuation">]</span><span class="token punctuation">[</span>048<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">13579</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">26</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>?:0<span class="token punctuation">[</span><span class="token number">48</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">2468</span><span class="token punctuation">]</span><span class="token punctuation">[</span>048<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">13579</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">26</span><span class="token punctuation">]</span><span class="token punctuation">)</span>00<span class="token punctuation">)</span>-02-29<span class="token punctuation">)</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>校验金额</strong>精确到2位小数。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>+<span class="token punctuation">(</span>.<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">)</span>?$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>校验手机号</strong>下面是国内 13、15、18开头的手机号正则表达式。（可根据目前国内收集号扩展前两位开头号码）</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span><span class="token number">13</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">14</span><span class="token punctuation">[</span><span class="token number">5</span><span class="token operator">|</span><span class="token number">7</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">15</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token operator">|</span><span class="token number">1</span><span class="token operator">|</span><span class="token number">2</span><span class="token operator">|</span><span class="token number">3</span><span class="token operator">|</span><span class="token number">5</span><span class="token operator">|</span><span class="token number">6</span><span class="token operator">|</span><span class="token number">7</span><span class="token operator">|</span><span class="token number">8</span><span class="token operator">|</span><span class="token number">9</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">18</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token operator">|</span><span class="token number">1</span><span class="token operator">|</span><span class="token number">2</span><span class="token operator">|</span><span class="token number">3</span><span class="token operator">|</span><span class="token number">5</span><span class="token operator">|</span><span class="token number">6</span><span class="token operator">|</span><span class="token number">7</span><span class="token operator">|</span><span class="token number">8</span><span class="token operator">|</span><span class="token number">9</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">\</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">8</span><span class="token punctuation">}</span>$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>判断IE的版本</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^.*MSIE <span class="token punctuation">[</span><span class="token number">5</span>-8<span class="token punctuation">]</span><span class="token punctuation">(</span>?:<span class="token punctuation">\</span><span class="token punctuation">\</span>.<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>+<span class="token punctuation">)</span>?<span class="token punctuation">(</span>?<span class="token operator">!</span>.*Trident<span class="token punctuation">\</span><span class="token punctuation">\</span>/<span class="token punctuation">[</span><span class="token number">5</span>-9<span class="token punctuation">]</span><span class="token punctuation">\</span><span class="token punctuation">\</span>.0<span class="token punctuation">)</span>.*$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>校验IP-v4地址</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">\</span><span class="token punctuation">\</span>b<span class="token punctuation">(</span>?:<span class="token punctuation">(</span>?:25<span class="token punctuation">[</span><span class="token number">0</span>-5<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">0</span>-4<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span>01<span class="token punctuation">]</span>?<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>?<span class="token punctuation">)</span><span class="token punctuation">\</span><span class="token punctuation">\</span>.<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">(</span>?:25<span class="token punctuation">[</span><span class="token number">0</span>-5<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">0</span>-4<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span>01<span class="token punctuation">]</span>?<span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span>?<span class="token punctuation">)</span><span class="token punctuation">\</span><span class="token punctuation">\</span>b
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>校验IP-v6地址</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token variable"><span class="token punctuation">((</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">7</span><span class="token punctuation">,</span><span class="token number">7</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">7</span>}<span class="token operator">:</span><span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">6</span>}<span class="token operator">:</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">5</span>}<span class="token punctuation">(</span><span class="token operator">:</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span>}<span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">(</span><span class="token operator">:</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span>}<span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">3</span>}<span class="token punctuation">(</span><span class="token operator">:</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span>}<span class="token punctuation">(</span><span class="token operator">:</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">5</span>}<span class="token operator">|</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">((</span><span class="token operator">:</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">6</span>}<span class="token punctuation">)</span><span class="token operator">|</span><span class="token operator">:</span><span class="token punctuation">((</span><span class="token operator">:</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">7</span>}<span class="token operator">|</span><span class="token operator">:</span><span class="token punctuation">)</span><span class="token operator">|</span>fe80<span class="token operator">:</span><span class="token punctuation">(</span><span class="token operator">:</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">)</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">%</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>zA<span class="token operator">-</span>Z]{<span class="token number">1</span><span class="token punctuation">,</span>}<span class="token operator">|</span><span class="token operator">:</span><span class="token operator">:</span><span class="token punctuation">(</span>ffff<span class="token punctuation">(</span><span class="token operator">:</span><span class="token number">0</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token punctuation">)</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}<span class="token punctuation">((</span><span class="token number">25</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">5</span>]<span class="token operator">|</span><span class="token punctuation">(</span><span class="token number">2</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">4</span>]<span class="token operator">|</span><span class="token number">1</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token punctuation">)</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token punctuation">)</span>\\.<span class="token punctuation">)</span>{<span class="token number">3</span><span class="token punctuation">,</span><span class="token number">3</span>}<span class="token punctuation">(</span><span class="token number">25</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">5</span>]<span class="token operator">|</span><span class="token punctuation">(</span><span class="token number">2</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">4</span>]<span class="token operator">|</span><span class="token number">1</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token punctuation">)</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>a<span class="token operator">-</span>fA<span class="token operator">-</span>F]{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">)</span>{<span class="token number">1</span><span class="token punctuation">,</span><span class="token number">4</span>}<span class="token operator">:</span><span class="token punctuation">((</span><span class="token number">25</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">5</span>]<span class="token operator">|</span><span class="token punctuation">(</span><span class="token number">2</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">4</span>]<span class="token operator">|</span><span class="token number">1</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token punctuation">)</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token punctuation">)</span>\\.<span class="token punctuation">)</span>{<span class="token number">3</span><span class="token punctuation">,</span><span class="token number">3</span>}<span class="token punctuation">(</span><span class="token number">25</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">5</span>]<span class="token operator">|</span><span class="token punctuation">(</span><span class="token number">2</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">4</span>]<span class="token operator">|</span><span class="token number">1</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token punctuation">)</span>{<span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span>}[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token punctuation">))</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>检查URL的前缀</strong></p> <p>应用开发中很多时候需要区分请求是HTTPS还是HTTP，通过下面的表达式可以取出一个url的前缀然后再逻辑判断。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>s.match<span class="token punctuation">(</span>/^<span class="token punctuation">[</span>a-zA-Z<span class="token punctuation">]</span>+:<span class="token punctuation">\</span><span class="token punctuation">\</span>/<span class="token punctuation">\</span><span class="token punctuation">\</span>//<span class="token punctuation">))</span>
<span class="token punctuation">{</span>
    s <span class="token operator">=</span> <span class="token string">'http://'</span> + s<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><strong>提取URL链接</strong></p> <p>下面的这个表达式可以筛选出一段文本中的URL。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span>f<span class="token operator">|</span>ht<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">(</span>tp<span class="token operator">|</span>tps<span class="token punctuation">)</span>:<span class="token punctuation">\</span><span class="token punctuation">\</span>/<span class="token punctuation">\</span><span class="token punctuation">\</span>/<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">\</span><span class="token punctuation">\</span>w-<span class="token punctuation">]</span>+<span class="token punctuation">\</span><span class="token punctuation">\</span>.<span class="token punctuation">)</span>+<span class="token punctuation">[</span><span class="token punctuation">\</span><span class="token punctuation">\</span>w-<span class="token punctuation">]</span>+<span class="token punctuation">(</span><span class="token punctuation">\</span><span class="token punctuation">\</span>/<span class="token punctuation">[</span><span class="token punctuation">\</span><span class="token punctuation">\</span>w- ./?%<span class="token operator">&amp;</span><span class="token operator">=</span><span class="token punctuation">]</span>*<span class="token punctuation">)</span>?
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>文件路径及扩展名校验</strong>验证windows下文件路径和扩展名（下面的例子中为.txt文件）</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span><span class="token punctuation">[</span>a-zA-Z<span class="token punctuation">]</span><span class="token punctuation">\</span><span class="token punctuation">\</span>:<span class="token operator">|</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">)</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">(</span><span class="token punctuation">[</span>^<span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">]</span>+<span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token punctuation">)</span>*<span class="token punctuation">[</span>^<span class="token punctuation">\</span><span class="token punctuation">\</span>/:*?&quot;<span class="token operator">&lt;&gt;</span><span class="token operator">|</span><span class="token punctuation">]</span>+<span class="token punctuation">\</span><span class="token punctuation">\</span>.txt<span class="token punctuation">(</span>l<span class="token punctuation">)</span>?$
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>提取网页颜色代码</strong>有时需要抽取网页中的颜色代码，可以使用下面的表达式。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token comment">#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>提取网页图片</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token operator">&lt;</span> *<span class="token punctuation">[</span>img<span class="token punctuation">]</span><span class="token punctuation">[</span>^<span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token operator">&gt;</span><span class="token punctuation">]</span>*<span class="token punctuation">[</span>src<span class="token punctuation">]</span> *<span class="token operator">=</span> *<span class="token punctuation">[</span><span class="token punctuation">\</span><span class="token punctuation">\</span><span class="token string">&quot;<span class="token entity" title="\\">\\</span>']{0,1}([^<span class="token entity" title="\\">\\</span>&quot;</span><span class="token punctuation">\</span><span class="token punctuation">\</span>'<span class="token punctuation">\</span><span class="token punctuation">\</span> <span class="token operator">&gt;</span><span class="token punctuation">]</span>*<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>提取页面超链接</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span><span class="token operator">&lt;</span>a<span class="token punctuation">\</span><span class="token punctuation">\</span>s*<span class="token punctuation">(</span>?<span class="token operator">!</span>.*<span class="token punctuation">\</span><span class="token punctuation">\</span>brel<span class="token operator">=</span><span class="token punctuation">)</span><span class="token punctuation">[</span>^<span class="token operator">&gt;</span><span class="token punctuation">]</span>*<span class="token punctuation">)</span><span class="token punctuation">(</span>href<span class="token operator">=</span><span class="token string">&quot;https?:<span class="token entity" title="\\">\\</span>/<span class="token entity" title="\\">\\</span>/)<span class="token variable"><span class="token punctuation">((</span><span class="token operator">?</span><span class="token operator">!</span><span class="token punctuation">(</span><span class="token operator">?</span><span class="token operator">:</span><span class="token punctuation">(</span><span class="token operator">?</span><span class="token operator">:</span>www\\.<span class="token punctuation">)</span><span class="token operator">?</span>'.implode<span class="token punctuation">(</span>'<span class="token operator">|</span><span class="token punctuation">(</span><span class="token operator">?</span><span class="token operator">:</span>www\\.<span class="token punctuation">)</span><span class="token operator">?</span>'<span class="token punctuation">,</span> $follow_list<span class="token punctuation">)</span>.'<span class="token punctuation">))</span></span>[^&quot;</span><span class="token punctuation">]</span>+<span class="token punctuation">)</span>&quot;<span class="token punctuation">((</span>?<span class="token operator">!</span>.*<span class="token punctuation">\</span><span class="token punctuation">\</span>brel<span class="token operator">=</span><span class="token punctuation">)</span><span class="token punctuation">[</span>^<span class="token operator">&gt;</span><span class="token punctuation">]</span>*<span class="token punctuation">)</span><span class="token punctuation">(</span>?:<span class="token punctuation">[</span>^<span class="token operator">&gt;</span><span class="token punctuation">]</span>*<span class="token punctuation">)</span><span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>查找CSS属性</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span><span class="token punctuation">\</span>s*<span class="token punctuation">[</span>a-zA-Z<span class="token punctuation">\</span><span class="token punctuation">\</span>-<span class="token punctuation">]</span>+<span class="token punctuation">\</span><span class="token punctuation">\</span>s*<span class="token punctuation">[</span>:<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">\</span><span class="token punctuation">\</span>s<span class="token punctuation">[</span>a-zA-Z0-9<span class="token punctuation">\</span><span class="token punctuation">\</span>s.<span class="token comment">#]+[;]{1}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>抽取注释</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token operator">&lt;</span><span class="token operator">!</span>--<span class="token punctuation">(</span>.*?<span class="token punctuation">)</span>--<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>匹配HTML标签</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token operator">&lt;</span><span class="token punctuation">\</span><span class="token punctuation">\</span>/?<span class="token punctuation">\</span><span class="token punctuation">\</span>w+<span class="token variable"><span class="token punctuation">((</span>\\s<span class="token operator">+</span>\\w<span class="token operator">+</span><span class="token punctuation">(</span>\\s<span class="token operator">*=</span>\\s<span class="token operator">*</span><span class="token punctuation">(</span><span class="token operator">?</span><span class="token operator">:</span>&quot;.<span class="token operator">*</span><span class="token operator">?</span>&quot;<span class="token operator">|</span>'.<span class="token operator">*</span><span class="token operator">?</span>'<span class="token operator">|</span>[\\<span class="token operator">^</span>'&quot;<span class="token operator">&gt;</span>\\s]<span class="token operator">+</span><span class="token punctuation">))</span></span>?<span class="token punctuation">)</span>+<span class="token punctuation">\</span><span class="token punctuation">\</span>s*<span class="token operator">|</span><span class="token punctuation">\</span><span class="token punctuation">\</span>s*<span class="token punctuation">)</span><span class="token punctuation">\</span><span class="token punctuation">\</span>/?<span class="token operator">&gt;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="时间正则案例"><a href="#时间正则案例" class="header-anchor">#</a> 时间正则案例</h2> <p><strong>简单的日期判断（YYYY/MM/DD）</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">}</span><span class="token punctuation">(</span><span class="token punctuation">\</span>-<span class="token operator">|</span><span class="token punctuation">\</span>/<span class="token operator">|</span><span class="token punctuation">\</span>.<span class="token punctuation">)</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">1,2</span><span class="token punctuation">}</span><span class="token punctuation">\</span><span class="token number">1</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">1,2</span><span class="token punctuation">}</span>$ 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>演化的日期判断（YYYY/MM/DD| YY/MM/DD）</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">\</span>-<span class="token operator">|</span><span class="token punctuation">\</span>/<span class="token operator">|</span><span class="token punctuation">\</span>.<span class="token punctuation">)</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">1,2</span><span class="token punctuation">}</span><span class="token punctuation">\</span><span class="token number">3</span><span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">1,2</span><span class="token punctuation">}</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">4</span><span class="token punctuation">}</span>年<span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">1,2</span><span class="token punctuation">}</span>月<span class="token punctuation">\</span>d<span class="token punctuation">{</span><span class="token number">1,2</span><span class="token punctuation">}</span>日$<span class="token punctuation">)</span>$ 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>加入闰年的判断的</strong></p> <p>实例：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>^<span class="token variable"><span class="token punctuation">((</span><span class="token punctuation">((</span><span class="token number">1</span>[<span class="token number">6</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">2</span><span class="token operator">-</span><span class="token number">9</span>]\d<span class="token punctuation">)</span>\d{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token operator">?</span>[<span class="token number">13578</span>]<span class="token operator">|</span><span class="token number">1</span>[<span class="token number">02</span>]<span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token operator">?</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">12</span>]\d<span class="token operator">|</span><span class="token number">3</span>[<span class="token number">01</span>]<span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token variable"><span class="token punctuation">((</span><span class="token punctuation">(</span><span class="token number">1</span>[<span class="token number">6</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">2</span><span class="token operator">-</span><span class="token number">9</span>]\d<span class="token punctuation">)</span>\d{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token operator">?</span>[<span class="token number">13456789</span>]<span class="token operator">|</span><span class="token number">1</span>[<span class="token number">012</span>]<span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token operator">?</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">12</span>]\d<span class="token operator">|</span><span class="token number">30</span><span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token variable"><span class="token punctuation">((</span><span class="token punctuation">(</span><span class="token number">1</span>[<span class="token number">6</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">2</span><span class="token operator">-</span><span class="token number">9</span>]\d<span class="token punctuation">)</span>\d{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">0</span><span class="token operator">?</span><span class="token number">2</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token operator">?</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span><span class="token number">1</span>\d<span class="token operator">|</span><span class="token number">2</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">8</span>]<span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token variable"><span class="token punctuation">((</span><span class="token punctuation">(</span><span class="token number">1</span>[<span class="token number">6</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">2</span><span class="token operator">-</span><span class="token number">9</span>]\d<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">48</span>]<span class="token operator">|</span>[<span class="token number">2468</span>][<span class="token number">048</span>]<span class="token operator">|</span>[<span class="token number">13579</span>][<span class="token number">26</span>]<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">((</span><span class="token number">16</span><span class="token operator">|</span>[<span class="token number">2468</span>][<span class="token number">048</span>]<span class="token operator">|</span>[<span class="token number">3579</span>][<span class="token number">26</span>]<span class="token punctuation">)</span><span class="token number">00</span><span class="token punctuation">))</span></span>-0?2-29-<span class="token punctuation">))</span>$ 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>分析：</p> <p>什么是合法的日期范围？对于不同的应用场景，这个问题有不同的解释。这里采纳MSDN中的约定：</p> <blockquote><p><strong>DateTime</strong>值类 型表示 值 范 围 在公元（基督 纪 元）0001 年 1 月 1 日午夜12:00:00 到公元 (C.E.) 9999年12月31日晚上11:59:59之间的日期和时间</p></blockquote> <p>关于闰年的阐释。</p> <blockquote><p>关于公历闰年是这样规定的：地球绕太阳公转一周叫做一回归年，一回归年长365日5时48分 46秒。因此，公历规定有平年和闰年，平年一年有365日，比回归年短0.2422日，四年共短0.9688日，故每四年增加一日，这一年有366日，就是闰年。但四年增加一日比四个回归年又多0.0312日,400年后将多3.12日,故在400年中少设3个闰年,也就是在400年中只设97个闰年，这样公历年的平均长度与回归年就相近似了。由此规定：年份是整百数的必须是400的倍数才是闰年，例如1900年、2100年就不是闰年。</p></blockquote> <p>首先需要验证年份，显然，年份范围为 0001 - 9999，匹配 YYYY 的正 则 表达式为：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>其中 [0-9] 也可以表示为 \d，但 \d 不如 [0-9] 直观，因此下面我将一直采用 [0-9]</p> <p><strong>用正则表达式验证日期的难点有二：一是大小月份的天数不同，二是闰年的考虑。</strong></p> <p><strong>对于第一个难点，我们首先不考虑闰年，假设2月份都是28天，这样，月份和日期可以分成三种情况：</strong></p> <p>（1）月份为 1, 3, 5, 7, 8, 10, 12，天数范围为 01 - 31，匹配MM-DD的正则表达式为：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">13578</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">1</span><span class="token punctuation">[</span>02<span class="token punctuation">]</span><span class="token punctuation">)</span>-<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">3</span><span class="token punctuation">[</span>01<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>（2）月份为 4, 6, 9, 11，天数范围为 01-30，匹配MM-DD的正则表达式为：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">469</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">11</span><span class="token punctuation">)</span>-<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">30</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>（3）月份为 2，考虑平年情况，匹配MM-DD的正则表达式为：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>02-<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">0</span>-8<span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>根据上面的成果，我们可以得到匹配平年日期格式为YYYY-MM-DD的正则表达式：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">)</span>-<span class="token variable"><span class="token punctuation">((</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">13578</span>]<span class="token operator">|</span><span class="token number">1</span>[<span class="token number">02</span>]<span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">12</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span><span class="token number">3</span>[<span class="token number">01</span>]<span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token variable"><span class="token punctuation">((</span><span class="token number">0</span>[<span class="token number">469</span>]<span class="token operator">|</span><span class="token number">11</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">12</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span><span class="token number">30</span><span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token punctuation">(</span>02-<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">0</span>-8<span class="token punctuation">]</span><span class="token punctuation">))</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>接着我们来解决第二个难点：闰年的考虑。根据闰年的定义，我们可以将闰年分为两类：</strong></p> <p>（1）能被4整除但不能被100整除的年份。寻找后两位的变化规律，可以很快得到下面的正则匹配：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">48</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">2468</span><span class="token punctuation">]</span><span class="token punctuation">[</span>048<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">13579</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">26</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>（2）能被400整除的年份。能被400整除的数肯定能被100整除，因此后两位肯定是00，我们只要保证前两位能被4整除即可，相应的正则表达式为：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">48</span><span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">2468</span><span class="token punctuation">]</span><span class="token punctuation">[</span>048<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">3579</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">26</span><span class="token punctuation">]</span><span class="token punctuation">)</span>00 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>最强验证日期的正则表达式,添加了闰年的验证</strong></p> <p>这个日期正则表达式支持的日期格式如下所示。</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code>YYYY-MM-DD 
YYYY/MM/DD 
YYYY_MM_DD 
YYYY.MM.DD
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><strong>完整的正则表达式如下</strong></p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token variable"><span class="token punctuation">((</span><span class="token operator">^</span><span class="token punctuation">((</span><span class="token number">1</span>[<span class="token number">8</span><span class="token operator">-</span><span class="token number">9</span>]\d{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">2</span><span class="token operator">-</span><span class="token number">9</span>]\d{<span class="token number">3</span>}<span class="token punctuation">))</span></span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token operator">|</span><span class="token number">12</span><span class="token operator">|</span><span class="token number">0</span>?<span class="token punctuation">[</span><span class="token number">13578</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">[</span>01<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">0</span>?<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token variable"><span class="token punctuation">((</span><span class="token number">1</span>[<span class="token number">8</span><span class="token operator">-</span><span class="token number">9</span>]\d{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">2</span><span class="token operator">-</span><span class="token number">9</span>]\d{<span class="token number">3</span>}<span class="token punctuation">))</span></span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">11</span><span class="token operator">|</span><span class="token number">0</span>?<span class="token punctuation">[</span><span class="token number">469</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">30</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">0</span>?<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token variable"><span class="token punctuation">((</span><span class="token number">1</span>[<span class="token number">8</span><span class="token operator">-</span><span class="token number">9</span>]\d{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>[<span class="token number">2</span><span class="token operator">-</span><span class="token number">9</span>]\d{<span class="token number">3</span>}<span class="token punctuation">))</span></span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">0</span>-8<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">1</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">0</span>?<span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">2468</span><span class="token punctuation">]</span><span class="token punctuation">[</span>048<span class="token punctuation">]</span>00<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">29</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">3579</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">26</span><span class="token punctuation">]</span>00<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">29</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">89</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">48</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">29</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">2</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">48</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">29</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">89</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">2468</span><span class="token punctuation">]</span><span class="token punctuation">[</span>048<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">29</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">2</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">2468</span><span class="token punctuation">]</span><span class="token punctuation">[</span>048<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">29</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">89</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">13579</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">26</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">29</span><span class="token punctuation">)</span>$<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">(</span>^<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">2</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">13579</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">26</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>?2<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">[</span>-<span class="token punctuation">\</span>/<span class="token punctuation">\</span>._<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">29</span><span class="token punctuation">)</span>$<span class="token punctuation">))</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>闰年的2月份有29天，因此匹配闰年日期格式为YYYY-MM-DD的正则表达式为：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token variable"><span class="token punctuation">((</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">48</span>]<span class="token operator">|</span>[<span class="token number">2468</span>][<span class="token number">048</span>]<span class="token operator">|</span>[<span class="token number">13579</span>][<span class="token number">26</span>]<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">((</span><span class="token number">0</span>[<span class="token number">48</span>]<span class="token operator">|</span>[<span class="token number">2468</span>][<span class="token number">048</span>]<span class="token operator">|</span>[<span class="token number">3579</span>][<span class="token number">26</span>]<span class="token punctuation">)</span><span class="token number">00</span><span class="token punctuation">))</span></span>-02-29
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>最后，将平年和闰年的日期验证表达式合并，我们得到最终的验证日期格式为YYYY-MM-DD的正则表达式为：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token variable"><span class="token punctuation">((</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">3</span>}[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">2</span>}[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">1</span>}<span class="token operator">|</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">1</span>}[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">2</span>}<span class="token operator">|</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">3</span>}<span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">((</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">13578</span>]<span class="token operator">|</span><span class="token number">1</span>[<span class="token number">02</span>]<span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">12</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span><span class="token number">3</span>[<span class="token number">01</span>]<span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token variable"><span class="token punctuation">((</span><span class="token number">0</span>[<span class="token number">469</span>]<span class="token operator">|</span><span class="token number">11</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">12</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span><span class="token number">30</span><span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token punctuation">(</span>02-<span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">0</span>-8<span class="token punctuation">]</span><span class="token punctuation">))</span><span class="token punctuation">))</span><span class="token operator">|</span><span class="token variable"><span class="token punctuation">((</span><span class="token punctuation">(</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">48</span>]<span class="token operator">|</span>[<span class="token number">2468</span>][<span class="token number">048</span>]<span class="token operator">|</span>[<span class="token number">13579</span>][<span class="token number">26</span>]<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">((</span><span class="token number">0</span>[<span class="token number">48</span>]<span class="token operator">|</span>[<span class="token number">2468</span>][<span class="token number">048</span>]<span class="token operator">|</span>[<span class="token number">3579</span>][<span class="token number">26</span>]<span class="token punctuation">)</span><span class="token number">00</span><span class="token punctuation">))</span></span>-02-29<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>DD/MM/YYYY*格式的正则验证表达式为</strong>：</p> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token variable"><span class="token punctuation">((</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">12</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span><span class="token number">3</span>[<span class="token number">01</span>]<span class="token punctuation">)</span><span class="token operator">/</span><span class="token punctuation">((</span><span class="token number">0</span>[<span class="token number">13578</span>]<span class="token operator">|</span><span class="token number">1</span>[<span class="token number">02</span>]<span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token variable"><span class="token punctuation">((</span><span class="token number">0</span>[<span class="token number">1</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span>[<span class="token number">12</span>][<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]<span class="token operator">|</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token operator">/</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">469</span>]<span class="token operator">|</span><span class="token number">11</span><span class="token punctuation">))</span></span><span class="token operator">|</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token number">2</span><span class="token punctuation">[</span><span class="token number">0</span>-8<span class="token punctuation">]</span><span class="token punctuation">)</span>/<span class="token punctuation">(</span>02<span class="token punctuation">))</span>/<span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">}</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token operator">|</span><span class="token punctuation">[</span><span class="token number">1</span>-9<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-9<span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">))</span><span class="token operator">|</span><span class="token punctuation">(</span><span class="token number">29</span>/02/<span class="token variable"><span class="token punctuation">((</span>[<span class="token number">0</span><span class="token operator">-</span><span class="token number">9</span>]{<span class="token number">2</span>}<span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">0</span>[<span class="token number">48</span>]<span class="token operator">|</span>[<span class="token number">2468</span>][<span class="token number">048</span>]<span class="token operator">|</span>[<span class="token number">13579</span>][<span class="token number">26</span>]<span class="token punctuation">)</span><span class="token operator">|</span><span class="token punctuation">((</span><span class="token number">0</span>[<span class="token number">48</span>]<span class="token operator">|</span>[<span class="token number">2468</span>][<span class="token number">048</span>]<span class="token operator">|</span>[<span class="token number">3579</span>][<span class="token number">26</span>]<span class="token punctuation">)</span><span class="token number">00</span><span class="token punctuation">))</span></span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><strong>小伙伴们可先收藏，后查阅这些常用的正则表达式！</strong></p> <p>好了，今天就到这儿吧，我是冰河，大家有啥问题可以留言，也可以在微信上私信我，我看到后都会回复大家，最后，小伙伴们点赞、在看、留言，转发，走起呀~~</p> <h2 id="写在最后"><a href="#写在最后" class="header-anchor">#</a> 写在最后</h2> <blockquote><p>如果你觉得冰河写的还不错，请微信搜索并关注「 <strong>冰河技术</strong> 」微信公众号，跟冰河学习高并发、分布式、微服务、大数据、互联网和云原生技术，「 <strong>冰河技术</strong> 」微信公众号更新了大量技术专题，每一篇技术文章干货满满！不少读者已经通过阅读「 <strong>冰河技术</strong> 」微信公众号文章，吊打面试官，成功跳槽到大厂；也有不少读者实现了技术上的飞跃，成为公司的技术骨干！如果你也想像他们一样提升自己的能力，实现技术能力的飞跃，进大厂，升职加薪，那就关注「 <strong>冰河技术</strong> 」微信公众号吧，每天更新超硬核技术干货，让你对如何提升技术能力不再迷茫！</p></blockquote> <p><img alt="" data-src="https://img-blog.csdnimg.cn/20200906013715889.png" loading="lazy" class="lazy"></p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/binghe001/BingheGuide/edit/master/docs/md/core/java/basics/2022-04-28-全网最全正则表达式总结.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">2022/5/23</span></div></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/md/core/java/advanced/default.html">
          关于我
        </a>
        →
      </span></p></div> </main></div> <aside class="page-sidebar"> <div class="page-side-toolbar"><div class="option-box-toc-fixed"><div class="toc-container-sidebar"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:650px"><div style="font-weight:bold;text-align:center;">全网最全正则表达式总结</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html#冰河常用正则" class="toc-sidebar-link">冰河常用正则</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html#时间正则案例" class="toc-sidebar-link">时间正则案例</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html#写在最后" class="toc-sidebar-link">写在最后</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box-toc-over"><img src="/images/system/toc.png" class="nozoom"> <span class="show-txt">目录</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:550px"><div style="font-weight:bold;text-align:center;">全网最全正则表达式总结</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html#冰河常用正则" class="toc-sidebar-link">冰河常用正则</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html#时间正则案例" class="toc-sidebar-link">时间正则案例</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html#写在最后" class="toc-sidebar-link">写在最后</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box"><img src="/images/system/wechat.png" class="nozoom"> <span class="show-txt">手机看</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.9rem">微信扫一扫</span> <img height="180px" src="https://api.qrserver.com/v1/create-qr-code/?data=https://binghe001.github.io/md/core/java/basics/2022-04-28-%E5%85%A8%E7%BD%91%E6%9C%80%E5%85%A8%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93.html" style="margin:10px;">
                可以<b>手机看</b>或分享至<b>朋友圈</b></div></div></div></div> <div class="option-box"><img src="/images/system/toggle.png" width="30px" class="nozoom"> <span class="show-txt">左栏</span></div> <div class="option-box"><img src="/images/system/xingqiu.png" width="25px" class="nozoom"> <span class="show-txt">星球</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">实战项目<span style="font-size:8px;color:red;">「SpringCloud Alibaba实战项目」</span>、专属电子书、问题解答、简历指导、技术分享、晋升指导、视频课程</span> <img height="180px" src="/images/personal/xingqiu.png" style="margin:10px;"> <b>知识星球</b>：冰河技术
            </div></div></div></div> <div class="option-box"><img src="/images/system/wexin4.png" width="25px" class="nozoom"> <span class="show-txt">读者群</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">添加冰河微信<span style="color:red;">(hacker_binghe)</span>进冰河技术学习交流圈「无任何套路」</span> <img src="/images/personal/hacker_binghe.jpg" height="180px" style="margin:10px;">
                PS：添加时请备注<b>读者加群</b>，谢谢！
              </div></div></div></div> <div class="option-box"><img src="/images/system/download-2.png" width="25px" class="nozoom"> <span class="show-txt">下资料</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">扫描公众号，回复<span style="color:red;">“1024”</span>下载<span style="color:red;">100GB+</span>学习技术资料、PDF书籍、实战项目、简历模板等「无任何套路」</span> <img src="/images/personal/qrcode.png" height="180px" style="margin:10px;"> <b>公众号:</b> 冰河技术
              </div></div></div></div> <div class="option-box"><img src="/images/system/heart-1.png" width="25px" class="nozoom"> <span class="show-txt">赞赏我</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">鼓励/支持/赞赏我</span> <img height="180px" src="/images/personal/encourage-head.png" style="margin:5px;"> <br>1. 不靠它生存但仍希望得到你的鼓励；
                <br>2. 时刻警醒自己保持技术人的初心；
              </div></div></div></div> <!----> <div title="关于我" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/core/java/advanced/default.html"><img src="/images/system/next2.png" width="30px" class="nozoom"> <span class="show-txt">下一篇</span></a></div></div>  <!----> </aside></div><div class="global-ui"><div class="read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="read-more-btn" target="_self" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">阅读全文</a> <div id="btw-modal-wrap" style="display: none;"><div id="btw-mask" style="position: fixed; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.7; z-index: 999; background: rgb(0, 0, 0);"></div> <div id="btw-modal" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 300px; text-align: center; font-size: 13px; background: rgb(255, 255, 255); border-radius: 10px; z-index: 9999; font-family: PingFangSC-Regular, sans-serif;"><span id="btw-modal-close-btn" style="position: absolute; top: 5px; right: 15px; line-height: 34px; font-size: 34px; cursor: pointer; opacity: 0.2; z-index: 9999; color: rgb(0, 0, 0); background: none; border: none; outline: none;">×</span> <p id="btw-modal-header" style="margin-top: 40px; line-height: 1.8; font-size: 13px;">
                扫码或搜索：<span style="color: #E9405A; font-weight: bold;">冰河技术</span> <br>发送：<span id="fustack-token" class="token" style="color: #e9415a; font-weight: bold; font-size: 17px; margin-bottom: 45px;">290992</span> <br>即可<span style="color: #e9415a; font-weight: bold;">立即永久</span>解锁本站全部文章</p> <img src="/images/personal/qrcode.png" style="width: 180px; margin-top: 10px; margin-bottom: 30px; border: 8px solid rgb(230, 230, 230);"></div></div></div><div class="pay-read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="pay-read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="pay-read-more-btn" target="_blank" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">付费阅读</a></div></div></div>
    <script src="/assets/js/cg-styles.js?v=1653305936337" defer></script><script src="/assets/js/cg-4.js?v=1653305936337" defer></script><script src="/assets/js/cg-3.js?v=1653305936337" defer></script><script src="/assets/js/cg-46.js?v=1653305936337" defer></script><script src="/assets/js/cg-5.js?v=1653305936337" defer></script><script src="/assets/js/cg-6.js?v=1653305936337" defer></script><script src="/assets/js/cg-app.js?v=1653305936337" defer></script>
  </body>
</html>
